package com.anti.core.config.druid;

import com.alibaba.druid.pool.DruidDataSource;
import com.anti.jdbc.DBUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;


@Configuration
public class DruidDataSourceConfig {
    //绑定配置的bean
    @ConfigurationProperties(prefix = "spring.datasource")
    @Bean("dataSource")
    public DataSource dataSource(){
        return new DruidDataSource();
    }

    @Bean("dbUtils")
    DBUtils dbUtils(){
        return  new DBUtils(dataSource());
    }
    @Bean("transactionManager")
    PlatformTransactionManager transactionManager(){
        return new DataSourceTransactionManager(dataSource());
    }
}
